<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const p1 = new Promise((resolve, reject) => setTimeout(() => {
            reject(new Error('error.'))
            // resolve(100)
        }, 3000));
        async function fn() {
            try {
                const r = await p1;
                console.log(r);
            } catch (error) {
                console.log(error);
            }
        }
        // async function fn() {
        //     const r = await p1.catch((err) => {
        //         console.log(err);
        //     });
        //     console.log(r);
        // }
        fn();

    </script>
</body>

</html>